package unit_7;

public class Elevator 
{
	public boolean 		doorOpen 		= false; // default setting
	public int 			currentFloor	= 1; //default starting point
	public final int 	TOP_FLOOR 		= 10;
	public final int 	MIN_FLOORS 		= 1;
	
	public void openDoor()
	{
			System.out.println("Opening door.");
			if(doorOpen)
			{
				System.out.println("Doors Are Already Open");
			}else
			{
				doorOpen = true;
				System.out.println("Door is open.");
			}
	}
	
	public void closeDoor()
	{
			System.out.println("Cloosing Door.");
			if(!doorOpen)
			{
				System.out.println("Doors Are Already Closed");
			}else
			{
				doorOpen = false;
				System.out.println("Door is closed.");
			}
	}	
	//the function to go down, with checks
	public void goUp(int userChoice) throws InterruptedException
	{
		if(currentFloor == TOP_FLOOR)
		{
			System.out.println("Cannot Go Up, On The Top Floorasda");
			closeDoor();
		}else
		{
			System.out.println("Going up " + (userChoice - currentFloor) +  " floor(s).");
			closeDoorsToMoveUp(userChoice);
			openDoor();
			try {
			    Thread.sleep(1000);
			    closeDoor();
			} catch(InterruptedException ex) {
			    Thread.currentThread().interrupt();
			}
		}
	}
	
	//The function to go down, with checks
	public void goDown(int passedChoice) throws InterruptedException
	{
		if(currentFloor == MIN_FLOORS)
		{
			System.out.println("Cannot Go Down, On The Bottom Floor");
			closeDoor();
		}else
			{
				System.out.println("Going down " + (currentFloor - passedChoice) +  " floor(s).");
				closeDoorsToMoveDown(passedChoice);
				openDoor();
				try {
				    Thread.sleep(1000);
				    closeDoor();
				} catch(InterruptedException ex) {
				    Thread.currentThread().interrupt();
				}
				}
			}
					
	public void closeDoorsToMoveDown(int passedChoice)
	{	
		if(doorOpen)
			{
				System.out.println("Cannot Go Down With The Door Open");
				System.out.println("Floor: " + currentFloor);
				closeDoor();
			}else
			{
				currentFloor = passedChoice;
			}
	}
	public void closeDoorsToMoveUp(int passedChoice)
	{
		if(doorOpen)
			{
				System.out.println("Cannot Go Up With The Door Open");
				System.out.println("Going down " + passedChoice +  " floor(s).");
				closeDoor();
			}else
			
				currentFloor = passedChoice;
			}
	}
